package org.example.partitioner;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * KEYIN, map阶段输入的key的类型(每一行的): LongWritable
 * VALUEIN, map阶段输入的value类型:Text,  就是一行的文本
 * KEYOUT,
 * VALUEOUT
 */
public class WordCountMap extends Mapper<LongWritable, Text, Text, IntWritable> {
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, IntWritable>.Context context) throws IOException, InterruptedException {
        String line = value.toString();
        String[] words = line.split(" ");
        for (String word : words) {
            Text outKey = new Text();
            outKey.set(word);
            IntWritable outValue = new IntWritable(1);
            context.write(outKey, outValue);
        }
    }
}

